A program sample demonstrating the implementation of a PAP Server using the Open Transport API.
Changes in 1.0.3
Fixed a number of bugs found with the code
* modified readPacket routine to pass up empty packets so that they can be responded to with
an empty packet to the client with the eof bit set.
* protected against multiple unbind calls on an endpoint
* Renamed DoDisconnect to DoRcvDisconnect and implemented DoSndDisconnect
* Check for more errors in handler - in previous release the result of a call was not checked and and
error could have been returned
* implemented OTLookHandler function
* implemented the ActivateHandoffEndpoint function where the handoff endpoint is initialized, and bound
* fixed bug to OTRcvDisconnect where we were passing unit'd &discon parameters.
* set flags before making OT calls instead of after the call success to fix timing issues.
* implemented code to force an endpoint which doesn't properly unbind to be closed and re-opened.
* respond with an empty packet with EOF bit set when incoming packet that has EOF bit set. When this
happens, the incoming file is closed.
Changes in 1.0.2
The previous release, v1.0.1, showed how to use OptionManagement to enable SelfSend mode for an endpoint. However, the SelfSend feature implemented by this option is not the desired SelfSend behavior that is normally desired of a PAPSpooler. For example, with the OPT_SELFSEND option enabled, the LaserWriter Client running on the same node as the PAPServerSample, would not see the PAPServerSample. The SelfSend option provided by Open Transport mkaes it so that the endpoint which enables SelfSend and then sends out a broadcast packet, the broadcast will also be sent to the endpoint node as well.
The desired behavior is what the PSetSelfSend call provided, that is to make it so that broadcast calls originating from other AppleTalk services on the node, such as the LaserWriter Client, would be sent to the node itself, so that the PAPServerSample could respond. This revision of the program demonstrates how to use the undocumented ATALK_IOC_FULLSELFSEND option to enable the desired functionality.
Description
The PAPServerSample demonstrates the use of the Open Transport to create a Printer Access Protocol Server. This sample supports multiple simultaneous connections.
PAPServerSample demonstrates some of the following network programming techniques
1. Implementing a PAP Server which supports multiple handoff endpoints.
2. Using the OTIoctl to enable selfsend mode.
3. Using OptionManagement to enable the EOM (End-of-message option).
4. Using OptionManagement to set the default server message.
The sample provides a user option to make the OTServerLimits call and to also dump the packets that are received. Note that by default, the incoming packets are saved to a file called "SavedPAPFileXX". You can launch the server on the same system that you use the client to send data to the client.
Building the Code
This sample was built using the Metrowerks CodeWarrior Pro IDE 3.0 environment and the Open Transport 2.0.1 SDK interfaces and libraries.
To rebuild the project, open it in CodeWarrior, change the access path as appropriate to point to the Open Tpt Client Developer folder in the OT 1.1.2 (or newer) SDK, and choose Make from the Project menu.
Using the PAPServerSample
The PAPServersample creates a PAP Server entity on the network an responds to NBP Lookup requests for LaserWriter devices. To use the sample, launch the application. When asked, enter "n" to change options. The PAP server opens the server endpoint and is ready to receive printer traffic. You can use the LaserWriter Chooser item to select the PAPServerSample item in the current zone and print to it. You can do this from either the same system as is running the server or from a different Macintosh system.
As incoming jobs are processed by the server, a temp file will be created in the default folder, where the traffic is placed. You can change the option to have the server dump incoming packets by answering "y", when prompted to change options, then answer yes to the dump packet option.
The design of the server is to open an asynch endpoint and to process incoming connect requests and data indications at interrupt time. You can control the number of handoff endpoints using the HANDOFF_EP define at the beginning of the PAPServerSample.c file. PAP queries are processed immediately, passing back the default responses for each query. For non-PostScript queries, the incoming packets are queued to an OTQueue associated with the processing endpoint. At system task time, the each endpoint, the server inspects each queue to see if there is data to be processed. All data gets written to the temp file associated with the endpoint.
Limitations:
This sample reuires the presence of Open Transport 1.1.2 or greater.
This sample implements some quick and dirty routines to support the PostScript queries which the Apple LaserWriter client issues to determine the printer type and capabilities. The purpose of this sample is not to demonstrate PostScript query processing. Users are advised to use the parsing code as demonstrated in the file PAPPostScriptStuff.c, with care. and to check that the code properly identifies the PostScript queries for their printer and client.
Copyright (work in progress) Apple Computer, Inc
You may incorporate this sample code into your applications without restriction, though the sample code has been provided "AS IS" and the responsibility for its operation is 100% yours. However, what you are not permitted to do is to redistribute the source as "DSC Sample Code"
after having made changes. If you're going to re-distribute the source, we require that you make it clear in the source that the code was descended from Apple Sample Code, but that you've made changes.
Bug Reports:
If you find any bugs, please send them to "devsupport@apple.com" and include "Attn: Rich Kubota" and I will try to address them.